package com.demo.swingquickticket.swing.layoutUtil;

import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

@Slf4j
public class AppCheckBoxCellRenderer implements TableCellRenderer {
    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
        Component component = new JCheckBox();
        component.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                log.info("点击事件");
                JCheckBox checkBox = (JCheckBox) table.getValueAt(row, column);
                checkBox.setSelected(!checkBox.isSelected());
            }
        });
        return component;
    }
}
